package com.ar4j;

import java.util.ArrayList;
import java.util.Collection;

/**
 * Describes an active record dynamic method (findBy, findAllBy, countBy, native SQL, named query, etc.) 
 */
public class DynamicMethodMetadata {
  private DynamicMethodType methodType;
  private boolean isLockForUpdate;
  private boolean isUpdate;
  private Collection<String> parameters;
  private String sqlQuery;
  private String queryName;
  private Class<?> returnType;
  private Class<?> collectionReturnType;
    
  public DynamicMethodMetadata() {
    this.isLockForUpdate = false;
    this.parameters = new ArrayList<String>();
  }
  
  public DynamicMethodType getMethodType() {
    return methodType;
  }

  public void setMethodType(DynamicMethodType methodType) {
    this.methodType = methodType;
  }

  public boolean getIsLockForUpdate() {
    return isLockForUpdate;
  }

  public void setIsLockForUpdate(boolean isLockForUpdate) {
    this.isLockForUpdate = isLockForUpdate;
  }

  public boolean getIsUpdate() {
    return isUpdate;
  }

  public void setIsUpdate(boolean isUpdate) {
    this.isUpdate = isUpdate;
  }

  public Collection<String> getParameters() {
    return parameters;
  }

  public void setParameters(Collection<String> parameters) {
    this.parameters = parameters;
  }
  
  public String getSqlQuery() {
    return sqlQuery;
  }

  public void setSqlQuery(String sqlQuery) {
    this.sqlQuery = sqlQuery;
  }

  public String getQueryName() {
    return queryName;
  }

  public void setQueryName(String queryName) {
    this.queryName = queryName;
  }

  public Class<?> getReturnType() {
    return returnType;
  }

  public void setReturnType(Class<?> returnType) {
    this.returnType = returnType;
  }
  
  public Class<?> getCollectionReturnType() {
    return collectionReturnType;
  }

  public void setCollectionReturnType(Class<?> collectionReturnType) {
    this.collectionReturnType = collectionReturnType;
  }

  public static enum DynamicMethodType {
    FIND_BY     ("findBy"),
    FIND_ALL_BY ("findAllBy"),
    COUNT_BY    ("countBy"),
    NATIVE_SQL  (""),
    NAMED_QUERY (""),
    EXISTS_BY    ("existsBy"),
    DELETE_BY    ("deleteBy"),;
    
    private String methodNamePrefix;
    private DynamicMethodType(String methodNamePrefix) { this.methodNamePrefix = methodNamePrefix; }
    public String getMethodNamePrefix() { return methodNamePrefix; }
  }
}
